// aysinc-wait
 





// Promise
// 回调函数

//  一个接口 要拿到数据 跑5个前置接口
const request = (arg,isReject)=>{
    return new Promise((resolve, reject)=>{
        setTimeout(()=>{
            if (isReject) {
                reject('出错啦');
                return;
            }
            console.log(arg);
            resolve(arg + 1);
        },1000);
    });
};


// async 函数返回的是一个promise
const fn = async ()=>{
    const res1 = await request(1);
    const res2 = await request(res1);
    const res3 = await request(res2);
    const res4 = await request(res3);
    const res5 = await request(res4);
    console.log(res5)
};



fn()




// const request = (arg, cb)=>{
//     setTimeout(()=>{
//         console.log(arg);
//         cb(arg +1 );
//     },300);
// };

// request(1, function(res1){
//     request(res1,function(res2){
//         request(res2,function(res3){
//             request(res3,function(res4){
//                 request(res4,function(res5){
//                     console.log('res5', res5)
//                 })
//             });
//         });
//     });
// });